//
//  GTNewfeatureViewController.m
//  GiftTalk
//
//  Created by Wan on 16/4/19.
//  Copyright © 2016年 Wan. All rights reserved.
//

#import "GTNewfeatureViewController.h"
#import "GTNewfeatureCell.h"


@implementation GTNewfeatureViewController

static NSString * const reuseIdentifier = @"Cell";

#pragma mark - Lift Cycle

- (instancetype)init {
    // 流水布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //1. 设置 layout 布局
    layout.itemSize = GTScreenBounds.size;
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    
    //2.设置滚动方向为水平
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    return [self initWithCollectionViewLayout:layout];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //1. Register cell classes
    [self.collectionView registerClass:[GTNewfeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    //2. 设置 collectionView 的属性
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.bounces = NO;
    self.collectionView.pagingEnabled = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    GTNewfeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.image = [UIImage imageNamed:[NSString stringWithFormat:@"walkthrough_%ld",indexPath.item + 1]];
    // 告诉 cell 当前显示的是哪个
    [cell setIndexPath:indexPath count:4];
    
    return cell;
}

#pragma mark - <UICollectionViewDelegate>
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%s, line = %d, indexPath = %zd", __FUNCTION__, __LINE__, indexPath.item);
}

@end
